#include "init.h"
#include "../EXCEPT/except.h"

extern int __TEXT_START, __TEXT_END;
extern int __BSS_START, __BSS_END;

void except_vector_init(){
    //两级跳转
    u32 b_code = 0xEA000000 + ((0x7BC0 - 0x08) >> 2);    // b 跳转
    u32 ldr_code = 0xE59FF018;  // ldr pc, [pc, #0x18]

    // Undef Handler
    UndefV = b_code;
    UndefVGoto = ldr_code;
    UndefVval = (u32)&except_und;

    // SWI Handler
    SWIV = b_code;
    SWIVGoto = ldr_code;
    SWIVval = (u32)&except_swi;

}

void bss_init(){
    int *start = &__BSS_START;
    int size = &__BSS_END - &__BSS_START;
    int i = 0;

    for(; i < size; i += 4){
        *(start + i) = 0;
    }
}